<?php
/**
 * Log Analysis model
 *
 * @author tamhv@fpt.net
 */
class Fpt_Log
{
    protected static $_instance = null;

    protected function __construct()
    {
        
    }

    public final static function getInstance()
    {
        if(is_null(self::$_instance))
        {
            self::$_instance = new self();
        }

        return self::$_instance;
    }

    /**
     * Push job send mail
     * @param int $type 1:action, 2: client, 3: api, 4:model
     * @param int $ex_code error code
     * @param string $ex_message error msg
     * @param string $ex_trace  error trace
     * @param string $request_info request params
     * @param string $request_url url
     * @return true 
     */
    
    public static function sendlog($type, $ex_code, $ex_message, $ex_trace, $request_info, $request_url)
    {
        if(APP_ENV == 'development')
        {
           var_dump('<pre><br><br><h2>'.$ex_message.'<br></h2><br>'.$ex_trace.'<br>');
        }
        $jobParams = array();
        $jobParams['class']     = 'JobLogError';
        $jobParams['function']  = 'sendErrorMessage';
        $jobParams['args']      = array(
            'type'                  => $type,
            'subject'               => 'Error Log',
            'error_code'            => $ex_code,
            'error_message'         => $ex_message,
            'stack_trace'           => $ex_trace,
            'time'                  => time(),
            'request_info'          => $request_info,
            'request_url'           => $request_url
        );

        //Create job client
        $jobClient = Fpt_Global::getJobClientInstance('sport');
        if($jobClient !== false)
        {
            //Register job
            $jobClient->doBackgroundTask(Fpt_Global::getJobFunction('sport','sendlog'), $jobParams);
        }
        // Return result
        return true;
    }
    	
}